﻿using AiMoRhino.Preview;
using Rhino;
using Rhino.Display;
using Rhino.DocObjects;
using Rhino.Geometry;
using System.Collections.Generic;
using System.Drawing;

namespace AiMoCore
{
    partial class CSharpScriptInstance
    {
        #region Preview

        Previewer previewer;
        internal void SetPreviewer(Previewer previewer)
        {
            this.previewer = previewer;
        }
        public void Show(object geometry, Color color)
        {
            previewer.Preview(geometry, color);
        }
        public void Show(object geometry)
        {
            previewer.Preview(geometry, Previewer.DefaultColor);
        }
        /// <summary>
        /// 重绘所有Rhino视图
        /// </summary>
        public void RedrawAll()
        {
            RhinoDoc.ActiveDoc.Views.Redraw();
        }
        /// <summary>
        /// 重绘当前Rhino视图
        /// </summary>
        public void Redraw()
        {
            RhinoDoc.ActiveDoc.Views.Redraw();
        }
        /// <summary>
        /// 清空当前预览的内容
        /// </summary>
        public void ClearShow()
        {
            previewer.Clear();
        }
        public void Show<T>(IEnumerable<T> geometries)
        {
            if (geometries is Polyline polyline)
            {
                previewer.Preview(polyline, Previewer.DefaultColor);
                return;
            }
            foreach (T geo in geometries)
                previewer.Preview(geo, Previewer.DefaultColor);
        }

        public void Show<T>(IEnumerable<T> geometries, Color color)
        {
            if (geometries is Polyline polyline)
            {
                previewer.Preview(polyline, color);
                return;
            }
            foreach (T geo in geometries)
                previewer.Preview(geo, color);
        }
        public void Show(Vector3d vector3d, Point3d from, Color color)
        {
            previewer.Preview(vector3d, from, color);
        }
        public void Show(Vector3d vector3d, Point3d from)
        {
            previewer.Preview(vector3d, from, Previewer.DefaultColor);
        }

        public void Show(string text, Point3d location, int height = 12)
        {
            Show(text, location, height, Previewer.DefaultColor);
        }
        public void Show(string text, Point3d location, int height, Color color)
        {
            TextDot textDot = new TextDot(text, location)
            {
                FontHeight = height,
            };
            Show(textDot, color);
        }
        public void Show(string text, Plane plane, double height)
        {
            Color color = Color.FromArgb(255, Previewer.DefaultColor);

            Show(text, plane, height, color);
        }
        public void Show(string text, Plane plane, double height, Color color)
        {
            Text3d text3D = new Text3d(text, plane, height)
            {
                HorizontalAlignment = TextHorizontalAlignment.Center,
                VerticalAlignment = TextVerticalAlignment.Middle,
            };
            Show(text3D, color);
        }
        #endregion
    }
}
